<%@ page language="java" import="java.util.*" contentType="text/html"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8" />
<title>调研问卷列表</title>
<link rel="stylesheet" type="text/css"
	href='<c:url value="/share/styles.css"></c:url>' />
<script src='<c:url value="/js/boot.js"></c:url>'></script>
<script src='<c:url value="/js/rqfui/rqfui.js"></c:url>'></script>
<style type="text/css">
body, html {
	width: 100%;
	height: 100%;
	margin: 0;
	font-family: "微软雅黑";
}

p {
	margin-left: 5px;
	font-size: 14px;
}

body {
	height: 100%;
	overflow: hidden;
}

.filterPan td {
	padding: 0;
}

.mini-splitter-pane {
	overflow: auto;
}

.mini-panel-body {
	padding: 0;
}

html body .searchbox .mini-buttonedit-icon {
	background: url('<c:url value="/share/img/magnifier-zoom.png"></c:url>')
		no-repeat 5% 5%;
}

.nameTitle {
	color: red;
}
.aTagUnderLine_body{
	position: absolute;
	display: none;
    z-index: 99;
	top: 0;
	left: 0;
	width:100%;
	height: 100%;
	background: rgba(0,0,0,.2);
}
.aTagUnderLine_alert{
    margin: 0 auto;
	width: 500px;
	height: 426px;
	position: relative;
	overflow: hidden;
    background: #ffffff;
    margin-top: 50px;
    z-index: 999;
    -webkit-box-shadow: 3px 3px 10px rgba(0,0,0,.8);
    box-shadow: 3px 3px 10px rgba(0,0,0,.8);
}
.aTagUnderLine_alert_title{
	position: relative;
    overflow: hidden;
    text-align: center;
	background: #2b5eae;
}
.aTagUnderLine_alert_title>div:nth-child(1){
	width: 150px;
	line-height: 33px;
	float: left;
	color: #fff;
	font-size: 14px;
}
.aTagUnderLine_alert_title>a{
	float: right;
	display: block;
	line-height: 33px;
	width: 33px;
    height: 33px;
	background: #ff6b6b;
	background: -ms-linear-gradient(top, #ff5555,  #ff7e7e);
	background:-moz-linear-gradient(top, #ff5555, #ff7e7e);
	background: -webkit-gradient(linear, 0% 0%, 0% 100%,from(#ff5555), to(#ff7e7e));
}
.aTagUnderLine_alert_title>a>img{
	margin: 12px;
}
.aTagUnderLine_alert_content{
	height: 357px;
	margin: 18px 30px;
	border: 1px solid #dddddd;
	position: relative;
    overflow: scroll;
    word-wrap: break-word;
    word-break: break-all;
}
#case_details>tr>td{
	padding-left: 50px;
	font-weight: 300;
	text-align: center;
    padding: 5px 0;
}
.table th{
	font-weight: 300;
}
.case_table>tbody>tr:nth-child(even){
	background: #edf3ff;
}
</style>
<script type="text/javascript">
	var stateValue = [ {
		id : -1,
		text : "全部"
	}, {
		id : 0,
		text : "草稿"
	}, {
		id : 1,
		text : "待评估"
	},{
		id : 2,
		text : "评估退回"
	}, {
		id : 3,
		text : "待审核"
	},{
		id : 4,
		text : "审核退回"
	}, {
		id : 5,
		text : "审核通过"
	} ];
</script>
</head>

<body>
	<div class="mini-toolbar"
		style="padding: 0px; border-width: 1px; border-bottom-width: 0px;">
		<table style="width: 100%;">
			<tr>
				<td style="width: 5px; height: 23px;"></td>
				<td width="100px"><a class="mini-button" id="rebackBtn"
					plain="true" iconCls="icon-list" onclick="status1">返回列表</a><a class="mini-button" id="addBtn" iconCls="icon-add"
					plain="true" onclick="add()">新增问卷</a></td>
				<td width="500px"><div id="typeBtn" class="mini-radiobuttonlist" repeatItems="1"
						repeatLayout="table" repeatDirection="vertical"
						style="margin-top: 4px;" textField="text"
						valueField="id" value="-1" onvaluechanged="typeChange"
						data=stateValue></div> </td>
				<td id = "bar" width="200px"><a class="mini-button" id="submitBtn_all" iconCls="icon-ok"
					plain="true" onclick="submit()">提交评估</a>
					<a class="mini-button" id="deleteBtn" iconCls="icon-remove"
					plain="true" onclick="_delete()">删除</a>
					</td>
				<td width="100px"><a class="mini-button" id="resetBtn"
					iconCls="icon-reset" plain="true" onclick="reloadList">刷新</a></td>
				<td></td>
				<td><span id="separatorId" class="separator">&nbsp;&nbsp;查询日期:&nbsp;&nbsp;<input
						id="starting" class="mini-datepicker" style="width: 100px;"
						showNullItem="false" valueField="" onvalidation=""
						allowInput="false" emptyText="起始期间..." nullItemText="&lt;无&gt;" />
						<span style="vertical-align: middle; margin: auto 5px; display: inline-block;">至</span>
						<input id="ending" class="mini-datepicker" style="width: 100px;"
						showNullItem="false" valueField="" onvalidation=""
						allowInput="false" emptyText="截止期间..." nullItemText="&lt;无&gt;" />
						<a class="mini-button" id="seachOrgBtn" iconCls="icon-mag"
						onclick="onselect" tooltip="查询" plain="true">查询</a>	
				</span></td>	
				<td style="width: 80px; height: 100%;">
					<div class="pageStatContainer">
						<div id="pageStatBtn_list"
							class="pageStat pageStatList pageStatListPress">
							<p>1</p>
						</div>
						<div id="pageStatBtn_form" class="pageStat pageStatForm">
							<p>2</p>
						</div>
						<div id="pageStatBtn_split" class="pageStat pageStatSplit">
							<p>3</p>
						</div>
					</div>
				</td>
			</tr>
		</table>
	</div>
	<div class="mini-fit">
		<div id="splitterPan" class="mini-splitter"
			style="width: 100%; height: 100%;" handlerSize="0">
			<div id='panLeft' size="400" showCollapseButton="true"
				style="padding: 0px; height: 100%; width: 100%;">
				<div id="datagrid1" class="mini-datagrid gridFull"
					borderStyle="border:1;" showReloadButton="true" pagesize="20"
					sizeList="[20,50,100,200]" allowCellWrap="true"
					allowHeaderWrap="true" idField="No" multiSelect="true"
					showPager="true" allowAlternating="true"
					ondrawcell="ondatagrid1DrawCell" onrowdblclick="gridRowDbClick"
					style="height: 100%; width: 100%; -moz-user-select: none; -webkit-user-select: none;"
					collapseGroupOnLoad="false" showColumnsMenu="true"
					showFilterRow="true" onshowrowdetail="onShowRowDetail">
					<div property="columns">
						<div type="indexcolumn" width="40px"></div>
						<div type="checkcolumn" width="40px"></div>
						<div field="Action" width="70px" headerAlign="center"
							align="center">
							<a class="mini-button" property="filter" id="removeBtn"
								iconCls="icon-broom" tooltip="清除筛选" onclick="removeSearch">清除
							</a>
						</div>
						<div field="name" width="200px" headerAlign="center"
							align="left" allowSort="true">
							问卷名称<input id="filter1" property="filter"
								class="mini-buttonedit searchbox" style="width: 100%;"
								onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
						</div>
						<!-- <div field="object" width="100px" headerAlign="center"
							align="left" allowSort="true">
							调研对象<input id="filter2" property="filter"
								class="mini-buttonedit searchbox" style="width: 100%;"
								onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
						</div> -->
						<div field="direction" width="100px" headerAlign="center"
							align="left" allowSort="true">
							调研方向<input id="filter2" property="filter"
								class="mini-buttonedit searchbox" style="width: 100%;"
						        onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
						</div>
						<div field="scale" width="100px" headerAlign="center"
							align="center" allowSort="true">调研规模
							<input id="filter3" property="filter"
								class="mini-buttonedit searchbox" style="width: 100%;"
						        onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
						</div>
						<div field="creater" width="100px" headerAlign="center"
							align="center" allowSort="true">组卷人
							<input id="filter4" property="filter"
								class="mini-buttonedit searchbox" style="width: 100%;"
								onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
						</div>
						<div field="createTime" width="185px" dateFormat="yyyy-MM-dd hh:mm:ss"
							headerAlign="center" align="center" allowSort="true">组卷日期</div>
						<div field="operation" width="110px" headerAlign="center"
							align="center" allowSort="true">操作</div>
						<div field="operation1" width="160px" headerAlign="center"
							align="center" allowSort="true">查看评估/审核意见</div>
						<!-- <div field="operation" width="100px"
							headerAlign="center" align="center" allowSort="true"></div> -->
						<div name="emptyCol" width='100%' headerAlign="center"
							align="center" cellStyle="padding:0;"></div>
					</div>
				</div>
			</div>
			<div id="panRight" showCollapseButton="true" expanded="false"
				style="overflow: hidden;">
				<iframe id=detailPan class="subPageFrame" frameborder="0"> </iframe>
			</div>
		</div>
	</div>
		<div class="aTagUnderLine_body">
		<div class="aTagUnderLine_alert">
			<div class="aTagUnderLine_alert_title">
				<div>查看评估/审核意见</div>
				<a href="#" onclick="closeAlert();" class="glyphicon glyphicon-remove">
					<img src="<c:url value='/share/images/Xdelete.png'></c:url>"></img>
				</a>
			</div>
			<div class="aTagUnderLine_alert_content">
				<table class="table case_table">
			    	<thead style="background: #c7e6fa; color: #2b5eae;">
				        <tr>
				          <th style="width: 170px;padding:5px 0;">评估/审核意见</th>
				          <th style="width: 170px;padding:5px 0;">评估/审核时间</th>
				          <th style="width: 170px;padding:5px 0;">评估/审核人</th>
				        </tr>
				    </thead>
			      <tbody id="case_details">
			      </tbody>
			    </table>
			</div>
		</div>
	</div>
	<script type="text/javascript">
		mini.parse();
		mini_debugger = false;
		var isKeepStat3 = false;
		var rootPath = '${rootPath}';
		var filterHelper = gridFilter();
		var datagrid1 = mini.get("datagrid1");
		var splitpan = mini.get("splitterPan");
		var typeBtn = mini.get("typeBtn");
		var filter1 = mini.get("filter1");
		var filter2 = mini.get("filter2");
		var filter3 = mini.get("filter3");
		var filter4 = mini.get("filter4");
		var starting = mini.get("starting");
		var ending = mini.get("ending");
		$(function() {
			$(".pageStat").hover(function() {
				$(this).addClass("hoverStyle");
			}, function() {
				$(this).removeClass("hoverStyle");
			});
			$(".pageStat").click(
					function() {
						$this = $(this);
						var value = $this.find("p").first().html();
						if (value == 1) {
							splitpan.collapsePane(2);
							$this.addClass("pageStatListPress");
							$this.next().removeClass("pageStatFormPress")
									.next().removeClass("pageStatSplitPress");
							isKeepStat3 = false;
							status1Show();
						}
						if (value == 2) {
							splitpan.collapsePane(1);
							$this.addClass("pageStatFormPress");
							$this.prev().removeClass("pageStatListPress");
							$this.next().removeClass("pageStatSplitPress");
							isKeepStat3 = false;
							status2Show();
						}
						if (value == 3) {
							splitpan.expandPane(1);
							splitpan.expandPane(2);
							$this.addClass("pageStatSplitPress");
							$this.prev().removeClass("pageStatFormPress")
									.prev().removeClass("pageStatListPress");
							isKeepStat3 = true;
							status3Show();
						}
					});
			status1();
			loadGrid1();
		});
		//双击
		function gridRowDbClick(e) {
			var id = e.row.id;
			showDetail(id);
		}
		function showDetail(id) {
			window.open(rootPath + '/surveyPaper/checkMv/' + id); 
		}
		function onselect() {
			var filterValue1 = filter1.getValue();
			var filterValue2 = filter2.getValue();
			var filterValue3 = filter3.getValue();
			var filterValue4 = filter4.getValue();
			var start = starting.getValue();
			var end = ending.getValue();
			filterHelper.clearFilterData();
			if (start && end && start > end) {
				top.commonTools.showTip("结束日期不能小于开始日期！", 2);
				return;
			}
			if (start != "") {
				var startTime = new Date(start);
				var tempTime = startTime.valueOf();
				startTime += 24 * 60 * 60 * 1000;
				startTime = new Date(tempTime);
				var year = startTime.getYear() + 1900;
				var month = startTime.getMonth() + 1;
				if (month < 10) {
					month = "0" + month;
				}
				var day = startTime.getDate();
				if (day < 10) {
					day = "0" + day;
				}
				start = year + "-" + month + "-" + day;
				var filterdata = filterHelper.formFilterData("createTime",
						start, '', 'GREATER_EQUALS', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if (end != "") {
				var filterdata = filterHelper.formFilterData("createTime",
						end, '', 'LESS_EQUALS', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if(filterValue1 != ""){
				var filterdata = filterHelper.formFilterData("name",
						filterValue1, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if(filterValue2 != ""){
				var filterdata = filterHelper.formFilterData("direction",
						filterValue2, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if(filterValue3 != ""){
				var filterdata = filterHelper.formFilterData("scale",
						filterValue3, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			} 
			if(filterValue4 != ""){
				var filterdata = filterHelper.formFilterData("creater",
						filterValue4, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			loadGrid1();
		}
		function loadGrid1() {
			var filterData = filterHelper.getFilterData();
			var postData = new Object();
			if (filterData != null || filterData.length > 0) {
				postData.filterdata = mini.encode(filterData);
			}
			var type = typeBtn.getValue();
			var url = "<c:url value='/surveyPaper/listData/' />" + type;
			datagrid1.load(url);
			datagrid1.load(postData);
		}
		function removeSearch() {
			filter1.setValue();
			filter1.setText();
			filter2.setValue();
			filter2.setText();
			filter3.setValue();
			filter3.setText();
			filter4.setValue();
			filter4.setText();
			starting.setValue();
			ending.setText();
			filterHelper.clearFilterData();
			loadGrid1();

		}
		function ondatagrid1DrawCell(e) {
			var row = e.row;
			var field = e.field;

			if (field == "Action") {
				var id = row.id;
				e.cellHtml = '<a class="aTagUnderLine" href="javascript:showDetail('
						+ id + ')">[查看]</a>';
			}
			if (field == "state") {
				if(row.state == 0){
					e.cellHtml="草稿";
				}
				if(row.state == 1){
					e.cellHtml="待评估";
				}
				if(row.state == 2){
					e.cellHtml="评估退回";
				}
				if(row.state == 3){
					e.cellHtml="待审核";
				}
				if(row.state == 4){
					e.cellHtml="审核退回";
				}
				if(row.state == 5){
					e.cellHtml="审核通过";
				}
			}
			if(field=="operation"){
				var id = row.id;
				if(row.state == 0 || row.state == 2 || row.state == 4){
					e.cellHtml = '<a class="aTagUnderLine" href="javascript:making(\''
						+ id + '\')">[编制]</a>'+'&nbsp;&nbsp<a class="aTagUnderLine" href="javascript:submit(\''
						+ id + '\')">[提交评估]</a>';
				}else if(row.state == 5&& row.isDistribute == 0){
					e.cellHtml = '<a class="aTagUnderLine" href="javascript:distribute(\''
						+ id + '\')">[分发]</a>';
				}else if(row.state == 5&& row.isDistribute == 1){
					e.cellHtml = '<a class="aTagUnderLine" href="javascript:total(\''
						+ id + '\')">[统计]</a>';
				}
			}
			if(field=="operation1"){
				var id = row.id;
				var state = row.state;
				if(state==2 || state==3){
					e.cellHtml = '<a class="aTagUnderLine" id="check" href="javascript:aTagUnderLine_alert(\''
						+ id + '\',\'0\',\''+state+'\');">[评估意见]&nbsp;&nbsp;</a>';
				}else if(state==4 || state==5){
					e.cellHtml ='<a class="aTagUnderLine" id="check" href="javascript:aTagUnderLine_alert(\''
						+ id + '\',\'0\',\''+state+'\');">[评估意见]&nbsp;&nbsp;</a>'
					+'<a class="aTagUnderLine" id="check" href="javascript:aTagUnderLine_alert(\''
					+ id + '\',\'1\',\''+state+'\');">[审核意见]&nbsp;&nbsp;</a>';
				} 
			}

		}
		function status1() {
			if (!isKeepStat3) {
				$("#pageStatBtn_list").click();
			}
			datagrid1.reload();
		}
		function status2() {
			if (!isKeepStat3) {
				$("#pageStatBtn_form").click();
			}
		}
		function status3() {
			$("#pageStatBtn_split").click();
		}
		function status1Show() {
			$("#bar").show();
			$('#rebackBtn').hide();
			$('#typeBtn').show();
			$('#resetBtn').show();
			$("#addBtn").show();
			$("#separatorId").show();
		}
		function status2Show() {
			$('#rebackBtn').show();
			$('#typeBtn').hide();
			$('#resetBtn').hide();
			$("#addBtn").hide();
			$("#separatorId").hide();
			$("#bar").hide();
		}
		function status3Show() {
			$("#bar").show();
			$('#rebackBtn').hide();
			$('#typeBtn').show();
			$('#resetBtn').show();
			$("#addBtn").show();
			$("#separatorId").show();
		}
		function reloadList() {
			datagrid1.reload();
		}
		
		function add(){
			status2();
        	$('#detailPan').css('height', '100%').css('width', '100%').attr('src',
						'<c:url value="/surveyPaper/addMv" />');
		}
		function making(id){
			status2();
			$('#detailPan').css('height', '100%').css('width', '100%').attr('src',
					'<c:url value="/surveyPaper/makeMv/" />'+id);
		}
		function distribute(id){
			status2();
			$('#detailPan').css('height', '100%').css('width', '100%').attr('src',
					'<c:url value="/surveyPaper/distributeMv/" />'+id);
		}
		function total(id){
			status2();
			$('#detailPan').css('height', '100%').css('width', '100%').attr('src',
					'<c:url value="/surveyAnalyze/mv/" />'+id);
		}

		function submit(){
			var ids = datagrid1.getSelecteds();
			if(ids.length < 1){
				mini.alert("请选择！");
				return;
			}
			mini.confirm("确定提交评估？", "确定？",
	         function (action) {
	                if (action == "ok") {
	                	var url = rootPath + "/surveyPaper/submit";
	                	var id= "";
	        			for(var i = 0; i<ids.length;i++){
        					if(id == ""){
        						id = ids[i].id;
        					}else{
        						id += ","+ids[i].id;
        					}
	        			}
	        			$.ajax({
	        				url:url,
	        				method:"post",
	        				dataType:"json",
	        				data:{'data':id},
	        				success:function(data){
	        					if(data){
	        						top.commonTools.showTip("操作成功!", 1);
	        						reloadList();
	        					}else{
	        						top.commonTools.showTip("操作失败!", 2);
	        					}
	        				},
	        				error:function(){
	        					top.commonTools.showTip("失败!", 2);
	        				}
	        				
	        			});
	                }					
	            });
		}
		
		function _delete(){
			var ids = datagrid1.getSelecteds();
			var id = "";
			var url = rootPath + "/surveyPaper/delete";
			if(ids.length >= 1){
				for(var i = 0; i<ids.length;i++){
					if(id == ""){
						id = ids[i].id;
					}else{
						id += ","+ids[i].id;
					}
					
				}
				mini.confirm("确定删除？", "确定？",
			            function (action) {
			                if (action == "ok") {
			                	$.ajax({
			        				url:url,
			        				method:"post",
			        				dataType:"json",
			        				data:{'data':id},
			        				success:function(data){
			        					if(data.isSuccess){
			        						top.commonTools.showTip("删除成功!", 1);
			        						datagrid1.reload();
			        					}else if(data.errorInfo){
			        						top.commonTools.showTip("没有权限删除!", 2);
			        					}else if(data.isUse){
			        						top.commonTools.showTip("已被引用,无法删除!", 2);
			        					}
			        				},
			        				error:function(){
			        					top.commonTools.showTip("失败!", 2);
			        				}
			        				
			        			});
			                } else {
			                	return;
			                }
			           });
			}else{
				top.commonTools.showTip("请选择!", 2);
			}
		}
		function typeChange(){
			var typeValue = typeBtn.getValue();
			if(typeValue == '0'){
				$("#deleteBtn").show();
				$("#submitBtn_all").show();
			}else if(typeValue == '2' || typeValue == '4'){
				$("#submitBtn_all").show();
				$("#deleteBtn").hide();
			}else{
				$("#submitBtn_all").hide();
				$("#deleteBtn").hide();
			}
			loadGrid1();
		}
		//点击弹出框
		function aTagUnderLine_alert(id,opera,state){
			var url=null;
			if(opera==0){
				url="<c:url value='/foreign/getEvalue/'/>"+id+"/1";
			}else if(opera==1){
				url="<c:url value='/foreign/getAudit/'/>"+id+"/1";
			}
			$.ajax({
				url: url,
				type:"get",
				dataType:"json",
				success:function(json){
					var html="";
					var time="";
					var content = "";
					var person = "";
					if(json){
					for(var i=0;i<json.length;i++){
						if(opera==0){
							time = json[i].evalueTime;
							content = json[i].evalueOpinion;
							person = json[i].evaluator;
							if(!content){
								content = "无";
							}
							if(time){
								time=time.substr(0,10);
							}
						}else if(opera==1){
							time = json[i].auditTime;
							content = json[i].auditOpinion;
							person = json[i].auditor;
							if(!content){
								content = "无";
							}
							if(time){
								time=time.substr(0,10);
							}
							
						}
						html+="<tr><td>"+content+"</td>"+
				          "<td>"+time+"</td><td>"+person+"</td></tr>";
					}
					}
					$("#case_details").html(html);
					$(".aTagUnderLine_body").show();
					
				}
			});
			
		}
		function closeAlert(){
			$(".aTagUnderLine_body").hide();
		}
	</script>
</body>
</html>
